# include<reg52.h>
# define uchar unsigned char
# define uint unsigned int
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^4;
void yanshi(uchar xms);
void writecommand(uchar x);
void writedate(uchar x);
void xianshi(uchar add,uchar date);
void init();
uchar miao=0,fen=0,shi=0,t=0,num;
uchar code shuzu[]="2020-6-09 09";

void main()
{
	init();
	while(1);
}

void yanshi(uchar xms)
{
	uchar i,j;
	for(i=xms;i>0;i--)
		for(j=110;j>0;j--);
}

void writecommand(uchar x)
{
	RS=0;
	E=0;
	P0=x;
	yanshi(5);
	E=1;
	yanshi(5);
	E=0;
}
void writedate(uchar x)
{
	RS=1;
	E=0;
	P0=x;
	yanshi(5);
	E=1;
	yanshi(5);
	E=0;
}

void xianshi(uchar add,uchar date)
{
	uchar shi,ge;
	shi=date/10;
	ge=date%10;
	writecommand(0x80+0x40+add);
	writedate(0x30+shi);
	writedate(0x30+ge);
}

void init()
{
	RW=0;
	E=0;
	writecommand(0x38);
	writecommand(0x0c);
	writecommand(0x06);
	writecommand(0x01);
	writecommand(0x80);

	for(num=0;num<12;num++)
	{
	writedate(shuzu[num]);
	yanshi(5);
	}
	writecommand(0x80+0x40+6);
	writedate(';');
	yanshi(5);
	writecommand(0x80+0x40+9);
	writedate(';');
	yanshi(5);
	xianshi(4,shi);
	xianshi(7,fen);
	xianshi(10,miao);
	TMOD=0x01;
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	EA=1;
	ET0=1;
	TR0=1;
}

void timer0() interrupt 1
{
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	t++;
	if(t==20)
	{
		t=0;
		miao++;
			if(miao==60)
			{
			miao=0;
			fen++;
				if(fen==60)
					{
						fen=0;
						shi++;
						if(shi==24)
						{
							shi=0;
						}
					xianshi(4,shi);
					}
				xianshi(7,fen);
			}
		xianshi(10,miao);
	}
}


